<template>
	<view class="provider">
		<!-- 信息显示 -->
		<view class="showuserinfo">
			<!-- 姓名 -->
			<view class="namesty">
				<!-- 图标 -->
				<view class="">
					 <image style="width: 100upx; height: 100upx; " 
					 src="../../static/myicons/nick2.png">
					 </image>
				</view>
				<view class="ziti"> {{OldNickName}} </view>
			</view>
			<!--联系电话 -->
			<view class="phonesty">
				<!-- 图标 -->
				<view class="">
					<image style="width: 100upx; height: 100upx; "  src="../../static/myicons/dian2.png">
					</image>
				</view>
				<view class="ziti"> {{oldPhone}} </view> 	
			</view>
		</view>
		<view class="phone_daohang">
			<!-- 拨打电话 -->
			 <view @click="makePhone()" >
			 	<image style="width: 100upx; height: 100upx; "  
			 	src="../../static/myicons/phone3.png">
			 	</image>
			 </view>
			 <!-- 开启导航 -->
			 <view class="" @click="openMap(oldlongitude,oldlatitude)">
				 <image style="width: 100upx; height: 100upx; "
				 src="../../static/myicons/daohang.png">
				 </image>
			 </view>
		</view>
<!-- 		
     <button class="daohang" type="primary" @click="openMap(oldlongitude,oldlatitude)">开启导航</button> -->
	<uni-icons @click="scanCode(eventId)" class="v-main-icon-scan" type="scan" color="#1aad19" size="140"></uni-icons>
	  <button  @click="termination()" class="termination" >帮助结束</button> 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				eventId:'', //帮助事件的id
				OldNickName:'张三',
				oldPhone:'1234567',  //老人的电话
				oldlatitude:'', //目标地址经纬度
				oldlongitude:'',
			}
		},
		onLoad(option) {	
			console.log("传递参数"); //获取帮助订单信息
			console.log(option.eventId); //获取帮助订单信息
			this.getEventData(option.eventId);
			this.eventId = option.eventId;
			console.log(this.eventId)
		},
		methods: {
			//帮助结束跳转评分页面
			termination(){
				console.log("结束")
			 uni.navigateTo({
				url: '../rate/rate?eventId=' + this.eventId
			 });
			},
             //拨打电话
			 makePhone(){
				 uni.makePhoneCall({	
				  // 手机号
				    phoneNumber: this.oldPhone, 
				 // 成功回调
				 success: (res) => {
				 console.log('调用成功!')	
				 },
				 // 失败回调
				 fail: (res) => {
				 console.log('调用失败!')
				 }
				   });
			 },
			//获取该帮助请求的所有信息
			getEventData(id){
				uniCloud.callFunction({
				    name:"provideHelp",
					data:{
						eventId:id,
					 	type:0, //为查询获取该事件和用户id  1为微信扫码结果提交
					},
					success: (res) => {
						console.log("事件信息");
						this.oldlatitude = res.result.data[0].oldlatitude;
						this.oldlongitude = res.result.data[0].oldlongitude;
						//获取志愿者名字
						uniCloud.callFunction({
							name:"findUserInfo",
							data:{
								userId:res.result.data[0].oldId,
							},
							success: (res) => {
								console.log("用户信息");
								console.log(res);
								this.OldNickName = res.result.data[0].nickname;
								this.oldPhone = res.result.data[0].username;
							}
						});	
			
					},
					fail: (err) => {
						console.log(err);
					} 
				});	
			},
			//扫描二维码的功能
			scanCode: function(id) {
					uni.scanCode({
						//onlyFromCamera: true, //只能从相机中获取，不能从图片中获取
						success: function(res) { //获取扫码结果
							console.log(res.result)
					
						uniCloud.callFunction({
							name:"provideHelp",
							data:{
								eventId:id,
								randomNumber:res.result,
								type:1, //1为微信扫码结果验证
							},
							success: (res) => {
								console.log("事件信息");	
									console.log(res);	
							if(res.result.affectedDocs == 0)
								return uni.showToast({title: '错误帮扶'});	
							if(res.result.data[0].helpComplete == 1)
								return uni.showToast({title: '开始帮助', duration:3000});
							},
							fail: (err) => {
								console.log(err);
							} 
						});	
							
						}
					});
				
				
			          },
		//打开地图 将待获取的经纬度 自己的经纬度 传入地图中
		openMap(lon,lat){
		                    console.log("获取经纬度ssssfff",lon,lat);
		                    //打开地图，并将门店位置传入
		                    uni.getLocation({
		                        success: res => {
		                            // res.latitude=lat;
		                            // res.longitude=lon;
		                            console.log('location success', parseFloat(lat),parseFloat(lon))
		                            uni.openLocation({
		                                latitude: parseFloat(lat),
		                                longitude:parseFloat(lon),
		                                scale: 18
		                            })
		                        }
		                    })
		                }
	
			
			
		}
	
	}
</script>

<style>
.provider{
	display: flex;
	flex-direction: column;
	align-items: center;
	font-size: 50upx;
	background-color: #F7F7F7;

}
.v-main-icon-scan{
	margin-top: 8%;
}
 .termination{
	margin-top: 100upx;
	border-radius: 25px;
	background-color: #f5da3f;
	border:1px solid #f5da3f;
	color: #FFFFFF;
	width: 60%;
 }
 .namesty{
 	 display: flex;
 	 align-items: center;
 	 height: 120upx;
 	 width: 80%; 
 	 margin-top: 30upx;
 	 
 }
 .phonesty{
 	 display: flex;	
 	 align-items: center;
 	 height: 140upx;
 	 width: 80%;
 }
 .showuserinfo{
 	  border:1px solid green;
 	  border-radius: 8%;
 	  width: 85%;
 	  padding-left: 25upx;
 	  margin-bottom: 35upx;
	  margin-top: 5%;
 }
 .ziti{
	font-size: 25px;
	font-weight: 550;
	color: #1aad19;
	margin-left: 20upx;
 }
 .phone_daohang{
	display: flex;
	justify-content: space-around;
	width: 90%;
	height: auto;
	margin-top: 30upx;
	
 }
</style>
